COMPILER_REPOSITORY := ../../prebuilts
PROJECT_DIR         := ../..
OUTROOT_HOME        := ../../out/obj
PROTOBUF_LIBDIR := $(COMCOMPILER_REPOSITORY)/protobuf/lib

LIFECYCLE_INC       := $(PROJECT_DIR)/system/inc/lifecycle
LIFECYCLE_LIB       := $(PROJECT_DIR)/system/lib/lifecycle

NAD_INC             := $(PROJECT_DIR)/system/inc/nad
NAD_LIB             := $(PROJECT_DIR)/system/lib/nad

LOCATION_INC        := ../../system/inc/location
LOCATION_LIB        := $(OUTROOT_HOME)/Loc_Service/lib

MCUCOMMGR_INC       := ../../framework/manager/DSVMCUCOMMGR/inc
MCUCOMMGR_LIB       := $(OUTROOT_HOME)/DSVMCUCOMMGR/lib

MCUCOMSVC_INC       := ../../framework/services/DSVMCUCOMSVC/inc

BINDER_INC          := ../../framework/libs/BinderLib/include
BINDER_LIB          := ../../out/obj/BinderLib/lib

LOG_LIB             := ../../out/obj/DSVLogMGR/lib
LOG_INC	            := ../../framework/manager/DSVLogMGR/inc

COMPILER_PREFIX     := arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-
CXX := $(COMPILER_REPOSITORY)/toolchain/usr/bin/$(COMPILER_PREFIX)g++
AR  := $(COMPILER_REPOSITORY)/toolchain/usr/bin/$(COMPILER_PREFIX)ar

INCDIR := ./inc
SRCDIR := ./src
OBJDIR := $(PWD)/../../out/obj/DSVEngineeringModeAPP/obj
LIBDIR := $(PWD)/../../out/obj/DSVEngineeringModeAPP/lib
BINDIR := $(PWD)/../../out/obj/DSVEngineeringModeAPP/bin
TARGET := DSVEngineeringModeAPP

SYSROOT := $(COMPILER_REPOSITORY)/sysroot
CFLAGS  := --sysroot=$(SYSROOT)
CFLAGS += -g -O2 -fpic
CFLAGS += -L. 
CFLAGS += -march=armv7-a
CFLAGS += -mtune=cortex-a8
CFLAGS += -mfloat-abi=softfp
CFLAGS += -mfpu=neon
CFLAGS += -mthumb-interwork
CFLAGS += -mno-thumb-interwork
CFLAGS += -Wno-write-strings
CFLAGS += -Wno-trigraphs
CFLAGS += -fno-tree-vectorize
CFLAGS += -fno-inline
CFLAGS += -fno-short-enums
CFLAGS += -Wundef
CFLAGS += -fexpensive-optimizations
CFLAGS += -frename-registers
CFLAGS += -fomit-frame-pointer
CFLAGS += -Dstrlcat=strncat
CFLAGS += -DHAVE_PTHREADS
CFLAGS += -DHAVE_ENDIAN_H
CFLAGS += -DHAVE_ANDROID_OS=1
CFLAGS += -std=c++11
CFLAGS += -DHAVE_SYS_UIO_H

LDFLAGS := $(CFLAGS)

LIBS := \
	-lpthread \
	-lrt \
	-lc \
	-lm \
	-lmcm \
	-lAppBase \
	-lAppManagerIPC \
    -lSVPCommu \
    -lgdbusapi \
    -lavm-service \
	-lDSVMCUCOMMGR \
	-lbinder \
	-lLocationApi \
	-lnadapi \
	-lDSVLogMGR\
	$(COMPILER_REPOSITORY)/sysroot/usr/lib/libgthread-2.0.so.0 \
	$(COMPILER_REPOSITORY)/sysroot/usr/lib/libgio-2.0.so.0 \
	$(COMPILER_REPOSITORY)/sysroot/usr/lib/libglib-2.0.so.0 \
	$(COMPILER_REPOSITORY)/sysroot/usr/lib/libgobject-2.0.so.0 \

LIBDIRS :=  \
	-L $(LIFECYCLE_LIB) \
	-L $(LOCATION_LIB) \
	-L $(MCUCOMMGR_LIB) \
	-L $(BINDER_LIB) \
	-L $(NAD_LIB) \
	-L $(COMPILER_REPOSITORY)/sysroot/usr/lib \
	-L $(LOG_LIB) \

LIB_LC := -L $(LIB_DIRS) \
          -L $(LIB_DIR_NAD) \
          -L $(PROTOBUF_LIBDIR)\
LIB_LC += -L $(OUTROOT_HOME)/DSVLogMGR/lib


INCPATHS := \
	-I $(INCDIR) \
	-I $(LOG_INC) \
	-I $(LIFECYCLE_INC) \
	-I $(LOCATION_INC) \
	-I $(MCUCOMSVC_INC) \
	-I $(MCUCOMMGR_INC) \
	-I $(BINDER_INC) \
	-I $(NAD_INC) \
	-I $(PROJECT_DIR)/sdk/inc \
	-I $(COMPILER_REPOSITORY)/sysroot/usr/include/glib-2.0 \
	-I $(COMPILER_REPOSITORY)/sysroot/usr/lib/glib-2.0/include \
	-I $(COMPILER_REPOSITORY)/sysroot/usr/include \
	-I ../../framework/manager \

SOURCES := \
	main.cpp \
	AppEvent.cpp \
	EngineeringApp.cpp \
	LocationMgr.cpp \
	MCUMgr.cpp \
	AudioControl.cpp \
	NadCallback.cpp \
	ATHandler.cpp \
	EMAppUtils.cpp \
	Ethernet.cpp \

OBJECTS := $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o))

$(BINDIR)/$(TARGET): $(OBJECTS)
	@-mkdir -p $(BINDIR) 2> /dev/null
	$(CXX) -o $@ $(LDFLAGS) $(OBJECTS) $(LIBDIRS) $(LIBS)

$(OBJECTS): $(OBJDIR)/%.o: $(SRCDIR)/%.cpp
	@-mkdir -p $(OBJDIR) 2> /dev/null
	$(CXX) -c $(CFLAGS) $(INCPATHS) -o $@  $<

all: $(OBJECTS) $(BINDIR)/$(TARGET)

clean:
	rm -f $(OBJECTS) $(BINDIR)/$(TARGET)
